package com.inossem.warehousestorage_inossem.request.up_frame;

import android.content.Context;

import com.google.gson.Gson;
import com.inossem.warehousestorage_inossem.bean.storage.StorageManageRespBean;
import com.inossem.warehousestorage_inossem.bean.up_frame.UpFrameOverviewBean;
import com.inossem.warehousestorage_inossem.bean.up_frame.UpFrameValidBean;
import com.inossem.warehousestorage_inossem.constant.RequestConstant;
import com.inossem.warehousestorage_inossem.listener.GsonBeanListener;
import com.inossem.warehousestorage_inossem.listener.StringRequestListener;
import com.inossem.warehousestorage_inossem.manage.RequestManage;
import com.inossem.warehousestorage_inossem.model.StringResponse;
import com.inossem.warehousestorage_inossem.request.Request;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2017/7/8 0008.
 */

public class UpFrameOverviewRequest extends Request {

    private static final String REQUEST_NUMBER = "stock_task_req_id";

    public static String request(Context context, String requestNumberStr, GsonBeanListener gsonBeanListener) {
        String tag;
        Map<String, String> params = new HashMap<>();
        params.put(REQUEST_NUMBER, requestNumberStr);
        String url = RequestManage.getUrl(context, RequestConstant.URL_UP_FRAME_OVERVIEW + RequestManage.mapEncodeToParams(params));
        tag = RequestManage.getHttpsGetWithLoading(context, url, new StringRequestListener() {
            @Override
            public void onSuccess(StringResponse stringRequestResponse) {
                Gson gson = new Gson();
                UpFrameOverviewBean bean = gson.fromJson(stringRequestResponse.getResponseInfo(), UpFrameOverviewBean.class);
                excuteJsonBeanNew(context, bean, gsonBeanListener);
            }
        });
        return tag;
    }

    public static String valid(Context context, UpFrameValidBean bean, GsonBeanListener gsonBeanListener) {
        String tag;
        Gson gson = new Gson();
        String url = RequestManage.getUrl(context, RequestConstant.URL_UP_FRAME_VALID);
        String body = gson.toJson(bean);
        tag = RequestManage.getHttpsPostWithLoading(context, url, body, new StringRequestListener() {
            @Override
            public void onSuccess(StringResponse stringRequestResponse) {
                String json = stringRequestResponse.getResponseInfo();
                StorageManageRespBean bean = gson.fromJson(json, StorageManageRespBean.class);
                excuteJsonBeanNew(context, bean, gsonBeanListener);
            }
        });
        return tag;
    }
}
